package com.lc.cehui.ui.activity.home;

import android.os.Bundle;
import android.text.Html;
import android.view.View;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.request.RequestOptions;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.hjq.http.EasyHttp;
import com.hjq.http.listener.HttpCallback;
import com.lc.cehui.R;
import com.lc.cehui.app.AppActivity;
import com.lc.cehui.http.glide.GlideApp;
import com.lc.cehui.http.request.CollectAddApi;
import com.lc.cehui.http.request.CollectDelApi;
import com.lc.cehui.http.request.CompanyListJobShowApi;
import com.lc.cehui.http.response.BaseBean;
import com.lc.cehui.http.response.CompanyListJobShowBean;
import com.lc.cehui.http.response.PerBean;
import com.lc.cehui.other.IntentKey;
import com.lc.cehui.util.SPUtil;

import org.jetbrains.annotations.NotNull;

import java.util.ArrayList;
import java.util.List;

import androidx.recyclerview.widget.RecyclerView;
import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class ParticularsDetailsActivity extends AppActivity {
    @BindView(R.id.tv_title)
    TextView tvTitle;
    @BindView(R.id.tv_tag)
    TextView tvTag;
    @BindView(R.id.recyclerView2)
    RecyclerView recyclerView2;
    @BindView(R.id.rv_tiaojian)
    RecyclerView rvTiaojian;
    @BindView(R.id.tv_jianjie)
    TextView tvJianjie;
    @BindView(R.id.img_logo)
    ImageView imgLogo;
    @BindView(R.id.tv_name)
    TextView tvName;
    @BindView(R.id.tv_lable)
    TextView tvLable;
    @BindView(R.id.tv_salary)
    TextView tvSalary;
    @BindView(R.id.img_shouchang)
    CheckBox checkbox;
    @BindView(R.id.recyclerView)
    RecyclerView recyclerView;
     private BaseQuickAdapter<CompanyListJobShowBean.DataBean.CompanyJobBean.WelfareBean, BaseViewHolder>  rv2adapter;
    private BaseQuickAdapter<PerBean, BaseViewHolder>  tiaojianadapter;
    private BaseQuickAdapter<CompanyListJobShowBean.DataBean.CompanyJobTuiBean, BaseViewHolder>  adapter;
    List<CompanyListJobShowBean.DataBean.CompanyJobBean.WelfareBean> rv2dataList = new ArrayList<>();
    List<CompanyListJobShowBean.DataBean.CompanyJobTuiBean> dataList = new ArrayList<>();
    List<PerBean> tiaojianList = new ArrayList<>();
    List<PerBean> list = new ArrayList<>();
    private String type_pid;
    private String type_id;
    private String id;

    @Override
    protected int getLayoutId() {
        return R.layout.activity_particularsdetails;
    }

    @Override
    protected void initView() {
       rv2adapter=new BaseQuickAdapter<CompanyListJobShowBean.DataBean.CompanyJobBean.WelfareBean, BaseViewHolder>(R.layout.item_gongsifuli2,rv2dataList) {
           @Override
           protected void convert(@NotNull BaseViewHolder holder, CompanyListJobShowBean.DataBean.CompanyJobBean.WelfareBean datebean) {
                holder.setText(R.id.tv_name,datebean.getWelfare());
           }
       };
       recyclerView2.setAdapter(rv2adapter);
        tiaojianadapter=new BaseQuickAdapter<PerBean, BaseViewHolder>(R.layout.item_tiaojian,tiaojianList) {
            @Override
            protected void convert(@NotNull BaseViewHolder holder, PerBean datebean) {
                holder.setText(R.id.tv_title,datebean.getName());
                holder.setText(R.id.tv_content,datebean.getCount());
            }
        };
        rvTiaojian.setAdapter(tiaojianadapter);

        adapter=new BaseQuickAdapter<CompanyListJobShowBean.DataBean.CompanyJobTuiBean, BaseViewHolder>(R.layout.item_gongsizhiwei,dataList) {
            @Override
            protected void convert(@NotNull BaseViewHolder baseViewHolder, CompanyListJobShowBean.DataBean.CompanyJobTuiBean dataBean) {
                baseViewHolder.setText(R.id.tv_name,dataBean.getTitle());
                baseViewHolder.setText(R.id.tv_tag, dataBean.getWork_city()+ dataBean.getWork_district()+"  ｜  "+dataBean.getYears()+"  ｜  "+ dataBean.getEducation());
                baseViewHolder.setText(R.id.tv_salary,dataBean.getSalary());
                RecyclerView recyclerView2=baseViewHolder.getView(R.id.recyclerView2);

                BaseQuickAdapter<CompanyListJobShowBean.DataBean.WelfareBean, BaseViewHolder> adapter=new BaseQuickAdapter<CompanyListJobShowBean.DataBean.WelfareBean, BaseViewHolder>(R.layout.item_gongsifuli2,dataBean.getWelfare()) {
                    @Override
                    protected void convert(@NotNull BaseViewHolder holder, CompanyListJobShowBean.DataBean.WelfareBean item) {
                        holder.setText(R.id.tv_name,item.getWelfare());
                    }
                };
                recyclerView2.setAdapter(adapter);

            }
        };
        recyclerView.setAdapter(adapter);
        checkbox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
                if (b) {
                    collect_add();
                } else {
                    collect_del();
                }
            }
        });

    }

    @Override
    protected void initData() {
        company_listjob_show();




    }
    private void collect_del() {
        EasyHttp.post(this)
                .api(new CollectDelApi().setUserid(SPUtil.get(this, IntentKey.USERID, 0)).setType(2).setStore_id("").setType_pid(type_pid).setType_id(type_id).setArticle_id(id).setWork_ids(id))
                .request(new HttpCallback<BaseBean>(this) {
                    @Override
                    public void onSucceed(BaseBean data) {

                        if (callBackCode(data)) {
                            toast("已取消收藏");
                        }
                    }
                });
    }

    private void collect_add() {
        EasyHttp.post(this)
                .api(new CollectAddApi().setUserid(SPUtil.get(this, IntentKey.USERID, 0)).setType(2).setStore_id("").setType_pid(type_pid).setType_id(type_id).setArticle_id(id).setWork_ids(id))
                .request(new HttpCallback<BaseBean>(this) {
                    @Override
                    public void onSucceed(BaseBean data) {


                    }
                });

    }
    private void company_listjob_show() {
        EasyHttp.post(this)
                .api(new CompanyListJobShowApi().setCompany_id(getIntent().getStringExtra("company_id")).setJob_id(getIntent().getStringExtra("job_id")).setUserid(SPUtil.get(this,IntentKey.USERID,0)))
                .request(new HttpCallback<CompanyListJobShowBean>(this) {
                    @Override
                    public void onSucceed(CompanyListJobShowBean data) {
                        tiaojianList.add(new PerBean("招聘人数",data.getData().getCompany_job().getPer()+""));
                        tiaojianList.add(new PerBean("到岗期限",data.getData().getCompany_job().getTerm()+""));
                        tiaojianList.add(new PerBean("职业技能",data.getData().getCompany_job().getSkill()+""));
                        tiaojianList.add(new PerBean("工作性质",data.getData().getCompany_job().getNature()+""));
                        tiaojianadapter.setNewData(tiaojianList);
                        tiaojianadapter.notifyDataSetChanged();
                        tvTitle.setText(data.getData().getCompany_job().getTitle());
                        tvTag.setText(data.getData().getCompany_job().getWork_city()+data.getData().getCompany_job().getWork_district()+"  |  "+data.getData().getCompany_job().getYears()+"  |  "+data.getData().getCompany_job().getEducation());
                        tvSalary.setText(data.getData().getCompany_job().getSalary());

                        tvJianjie.setText(Html.fromHtml(data.getData().getCompany_job().getContent()));
                        rv2dataList.addAll(data.getData().getCompany_job().getWelfare());
                        rv2adapter.setNewData(rv2dataList);
                        rv2adapter.notifyDataSetChanged();
                        dataList.addAll(data.getData().getCompany_job_tui());
                        adapter.setNewData(dataList);
                        adapter.notifyDataSetChanged();
                        id = data.getData().getCompany_job().getJob_id()+"";
                        type_pid = data.getData().getCompany_job().getType_pid()+"";
                        type_id = data.getData().getCompany_job().getType_id()+"";
                        if (data.getData().getCompany_job().getIs_collect() == 1) {
                            checkbox.setChecked(false);
                        } else {
                            checkbox.setChecked(true);
                        }
                        GlideApp.with(ParticularsDetailsActivity.this).load(data.getData().getCompany().getPicurl()).apply(new RequestOptions().placeholder(R.mipmap.logo_qyzp).error(R.mipmap.logo_qyzp)).into((ImageView)imgLogo);
                        tvTitle.setText(data.getData().getCompany().getName());
                        tvLable.setText(data.getData().getCompany().getCity()+"  |  "+data.getData().getCompany().getDistrict()+"  |  "+data.getData().getCompany().getScale());
                    }
                });
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // TODO: add setContentView(...) invocation
        ButterKnife.bind(this);
    }

    @OnClick({R.id.img_back, R.id.img_jubao, R.id.img_shouchang})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.img_back:
                finish();
                break;
            case R.id.img_jubao:
                startActivity(ComplaintActivity.class);
                break;
            case R.id.img_shouchang:

                break;
        }
    }
}
